import { createHash } from 'crypto'
import type { ArgumentsCamelCase } from 'yargs'
import type { OptionsType } from '@/types'

export function generateToken(key: string, secretKey: string) {
  const timespan = Math.floor(Date.now() / 1000).toString()
  const originStr = key + timespan + secretKey
  const token = createHash('md5').update(originStr).digest('hex').toUpperCase()
  return { token, timespan }
}

export function getOptions(
  argv: ArgumentsCamelCase,
  pkg: {
    name: string
    version: string
  },
) {
  return {
    name: pkg.name,
    version: pkg.version,
    port: argv.port,
  } as OptionsType
}
